package com.example.farm.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.farm.Bean.Land;
import com.example.farm.mapper.LandMapper;
import com.example.farm.service.LandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 姚
 * @since 2023-04-15
 */
@Service
@Transactional
public class LandServiceImpl extends ServiceImpl<LandMapper, Land> implements LandService {

    @Autowired
    private LandMapper landMapper;

    @Override
    public int updateLand(Land land) {
        if (land.getUid() == null){
            return landMapper.insert(land);
        }else {

            UpdateWrapper<Land> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("uid",land.getUid());
            updateWrapper.set("OwnerUid",land.getOwnerUid());
            updateWrapper.set("status",land.getStatus());
            updateWrapper.set("landPropertyStatus",land.getLandPropertyStatus());

            return landMapper.update(land,null);
        }
    }

    @Override
    public ArrayList<Land> selectAll() {
        return landMapper.selectAll();
    }

    @Override
    public int insertLand(Land land) {
        return landMapper.insert(land);
    }

    @Override
    public ArrayList<Land> selectByOwnerUid(String OwnerUid) {
        return landMapper.selectByOwnerUid(OwnerUid);
    }


}
